/* USER CODE BEGIN Header */
/**
  ******************************************************************************
  * File Name          : freertos.c
  * Description        : Code for freertos applications
  ******************************************************************************
  * @attention
  *
  * <h2><center>&copy; Copyright (c) 2021 STMicroelectronics.
  * All rights reserved.</center></h2>
  *
  * This software component is licensed by ST under Ultimate Liberty license
  * SLA0044, the "License"; You may not use this file except in compliance with
  * the License. You may obtain a copy of the License at:
  *                             www.st.com/SLA0044
  *
  ******************************************************************************
  */
/* USER CODE END Header */

/* Includes ------------------------------------------------------------------*/
#include "FreeRTOS.h"
#include "task.h"
#include "main.h"
#include "cmsis_os.h"

/* Private includes ----------------------------------------------------------*/
/* USER CODE BEGIN Includes */
#include "detect_task.h"
#include "calibrate_task.h"
#include "obtein_mineral_task.h"
#include "voltage_task.h"
#include "led_flow_task.h"
#include "chassis_task.h"
#include "test_task.h"
#include "ins_task.h"

#include "rescue_task.h" //by yanfubing
#include "fall_down_task.h" //by yanfubing
#include "rescue_IDcard_task.h" //by yanfubing 
#include "referee_usart_task.h"
/* USER CODE END Includes */

/* Private typedef -----------------------------------------------------------*/
/* USER CODE BEGIN PTD */

/* USER CODE END PTD */

/* Private define ------------------------------------------------------------*/
/* USER CODE BEGIN PD */

/* USER CODE END PD */

/* Private macro -------------------------------------------------------------*/
/* USER CODE BEGIN PM */

/* USER CODE END PM */

/* Private variables ---------------------------------------------------------*/
/* USER CODE BEGIN Variables */

/* USER CODE END Variables */
osThreadId TaskHandle;

/* Private function prototypes -----------------------------------------------*/
/* USER CODE BEGIN FunctionPrototypes */
osThreadId detect_handle;
osThreadId calibrate_tast_handle;
osThreadId obtein_mineral_handle;
osThreadId battery_voltage_handle;
osThreadId led_flow_Handle;
osThreadId chassis_TaskHandle;
osThreadId task_Handle;
osThreadId imuTask_Handle;

osThreadId rescuetask_Handle;   //by yan
osThreadId fall_downtask_Handle;  //by yan
osThreadId rescue_IDcard_Handle;  //by yan
osThreadId referee_usart_task_handle;
/* USER CODE END FunctionPrototypes */

void tast_Task(void const * argument);

extern void MX_USB_DEVICE_Init(void);
void MX_FREERTOS_Init(void); /* (MISRA C 2004 rule 8.1) */

/* GetIdleTaskMemory prototype (linked to static allocation support) */
void vApplicationGetIdleTaskMemory( StaticTask_t **ppxIdleTaskTCBBuffer, StackType_t **ppxIdleTaskStackBuffer, uint32_t *pulIdleTaskStackSize );

/* GetTimerTaskMemory prototype (linked to static allocation support) */
void vApplicationGetTimerTaskMemory( StaticTask_t **ppxTimerTaskTCBBuffer, StackType_t **ppxTimerTaskStackBuffer, uint32_t *pulTimerTaskStackSize );

/* USER CODE BEGIN GET_IDLE_TASK_MEMORY */
static StaticTask_t xIdleTaskTCBBuffer;
static StackType_t xIdleStack[configMINIMAL_STACK_SIZE];

void vApplicationGetIdleTaskMemory( StaticTask_t **ppxIdleTaskTCBBuffer, StackType_t **ppxIdleTaskStackBuffer, uint32_t *pulIdleTaskStackSize )
{
  *ppxIdleTaskTCBBuffer = &xIdleTaskTCBBuffer;
  *ppxIdleTaskStackBuffer = &xIdleStack[0];
  *pulIdleTaskStackSize = configMINIMAL_STACK_SIZE;
  /* place for user code */
}
/* USER CODE END GET_IDLE_TASK_MEMORY */

/* USER CODE BEGIN GET_TIMER_TASK_MEMORY */
static StaticTask_t xTimerTaskTCBBuffer;
static StackType_t xTimerStack[configTIMER_TASK_STACK_DEPTH];

void vApplicationGetTimerTaskMemory( StaticTask_t **ppxTimerTaskTCBBuffer, StackType_t **ppxTimerTaskStackBuffer, uint32_t *pulTimerTaskStackSize )
{
  *ppxTimerTaskTCBBuffer = &xTimerTaskTCBBuffer;
  *ppxTimerTaskStackBuffer = &xTimerStack[0];
  *pulTimerTaskStackSize = configTIMER_TASK_STACK_DEPTH;
  /* place for user code */
}
/* USER CODE END GET_TIMER_TASK_MEMORY */

/**
  * @brief  FreeRTOS initialization
  * @param  None
  * @retval None
  */
void MX_FREERTOS_Init(void) {
  /* USER CODE BEGIN Init */

  /* USER CODE END Init */

  /* USER CODE BEGIN RTOS_MUTEX */
  /* add mutexes, ... */
  /* USER CODE END RTOS_MUTEX */

  /* USER CODE BEGIN RTOS_SEMAPHORES */
  /* add semaphores, ... */
  /* USER CODE END RTOS_SEMAPHORES */

  /* USER CODE BEGIN RTOS_TIMERS */
  /* start timers, add new ones, ... */
  /* USER CODE END RTOS_TIMERS */

  /* USER CODE BEGIN RTOS_QUEUES */
  /* add queues, ... */
  /* USER CODE END RTOS_QUEUES */

  /* Create the thread(s) */
  /* definition and creation of Task */
  osThreadDef(Task, tast_Task, osPriorityNormal, 0, 128);
  TaskHandle = osThreadCreate(osThread(Task), NULL);

//    osThreadDef(REFEREE, referee_usart_task, osPriorityNormal, 0, 128);
//    referee_usart_task_handle = osThreadCreate(osThread(REFEREE), NULL);
  /* USER CODE BEGIN RTOS_THREADS */
//IMU
//  osThreadDef(imuTask, INS_task, osPriorityRealtime, 0,512);                    //已初步完成，uint16类型数据
//  imuTask_Handle = osThreadCreate(osThread(imuTask), NULL);

  osThreadDef(task, test_task, osPriorityNormal, 0, 128);         //完结
  task_Handle = osThreadCreate(osThread(task), NULL);

  //离线检测
  osThreadDef(detect, detect_task, osPriorityNormal, 0, 512);     //已初步完成
  detect_handle = osThreadCreate(osThread(detect), NULL);

  //校准任务
  osThreadDef(cali, calibrate_task, osPriorityNormal, 0, 512);    //待完成夹取的升降限位  电机ID设置
  calibrate_tast_handle = osThreadCreate(osThread(cali), NULL);

  //救援任务
  osThreadDef(mineral, rescue_obstacle_task, osPriorityNormal, 0, 512);
  rescuetask_Handle = osThreadCreate(osThread(mineral), NULL);

  //升降任务
  osThreadDef(Task1, fall_down_task, osPriorityNormal, 0, 512);
  fall_downtask_Handle = osThreadCreate(osThread(Task1), NULL);
//  //电源电压采集
//  osThreadDef(BATTERY_VOLTAGE, battery_voltage_task, osPriorityNormal, 0, 128);  //待完成
//  battery_voltage_handle = osThreadCreate(osThread(BATTERY_VOLTAGE), NULL);
  //心跳任务
  osThreadDef(led, led_flow_task, osPriorityNormal, 0, 128); //by yanfubing
  led_flow_Handle = osThreadCreate(osThread(led), NULL);
  //底盘任务
  osThreadDef(ChassisTask, chassis_task, osPriorityAboveNormal, 0, 512);
  chassis_TaskHandle = osThreadCreate(osThread(ChassisTask), NULL);
 //救援卡任务
  osThreadDef(rescue_id_task, rescue_IDcard_task, osPriorityAboveNormal, 0, 256);
  rescue_IDcard_Handle = osThreadCreate(osThread(rescue_id_task), NULL);

  /* USER CODE END RTOS_THREADS */

}

/* USER CODE BEGIN Header_tast_Task */
/**
  * @brief  Function implementing the Task thread.
  * @param  argument: Not used
  * @retval None
  */
/* USER CODE END Header_tast_Task */
__weak void tast_Task(void const * argument)
{
  /* init code for USB_DEVICE */
  MX_USB_DEVICE_Init();
  /* USER CODE BEGIN tast_Task */
  /* Infinite loop */
  for(;;)
  {
    osDelay(1);
  }
  /* USER CODE END tast_Task */
}

/* Private application code --------------------------------------------------*/
/* USER CODE BEGIN Application */

/* USER CODE END Application */
